<?php
/**
 * Created by PhpStorm.
 * User: 汪凤杰
 * Date: 2017/11/9
 * Time: 13:11
 */
if (is_file(__DIR__ . '/autoload.php')) {
    require_once __DIR__ . '/autoload.php';
}

use JSSDK\JSSDKClient;
use JSSDK\Core\JSSDKException;

class JSSDK
{

    private static $appid = '';
    private static $secret = '';
    private static $redirect_url = '';
    /**
     * 根据Config配置，得到一个JSSDKClient实例
     *
     * @return JSSDKClient 一个JSSDKClient实例
     */
    public static function getJSSDKClient($appid,$secret,$redirect_url)
    {
        session_start(); // 开启 session

        self::$appid = $appid;
        self::$secret = $secret;
        self::$redirect_url = $redirect_url;
        try {
            $jssdkClient = new JSSDKClient(self::$appid, self::$secret, self::$redirect_url);
        } catch (JSSDKException $e) {
            printf(__FUNCTION__ . "creating JSSDKClient instance: FAILED\n");
            printf($e->getMessage() . "\n");
            return null;
        }
        return $jssdkClient;
    }

    public static function println($message)
    {
        if (!empty($message)) {
            echo strval($message) . "\n";
        }
    }

}